import frida
import sys

str_host = "127.0.0.1:8877"
manager = frida.get_device_manager()
rdev = manager.add_remote_device(str_host)
session = rdev.attach("KaoShiYi")

scr = """
Java.perform(function () {
    var StringBuilder = Java.use("java.lang.StringBuilder");

    StringBuilder.toString.implementation = function () {
        var res = this.toString();
        console.log('hook的StringBuilder--->',res); 
        //console.log(Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Throwable").$new()));
        //console.log(send(Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Throwable").$new())))
        return res;
    }

});
"""
script = session.create_script(scr)


def on_message(message, data):
    print(message, data)


script.on("message", on_message)
script.load()
sys.stdin.read()
